home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / FileDescriptor.java < prev    next >
Text File  |  1998-09-22  |  4KB  |  105 lines

  1. /*
  2.  * @(#)FileDescriptor.java    1.11 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.io;
  16.  
  17. /**
  18.  * Instances of the file descriptor class serve as an opaque handle 
  19.  * to the underlying machine-specific structure representing an open 
  20.  * file or an open socket. 
  21.  * <p>
  22.  * Applications should not create their own file descriptors. 
  23.  *
  24.  * @author  Pavani Diwanji
  25.  * @version 1.11, 07/01/98
  26.  * @see        java.io.FileInputStream
  27.  * @see        java.io.FileOutputStream
  28.  * @see     java.net.SocketInputStream
  29.  * @see     java.net.SocketOutputStream
  30.  * @since   JDK1.0
  31.  */
  32. public final class FileDescriptor {
  33.  
  34.     private int fd; 
  35.  
  36.     /**
  37.      * A handle to the standard input stream. 
  38.      *
  39.      * @since   JDK1.0
  40.      */    
  41.     public static final FileDescriptor in 
  42.     = initSystemFD(new FileDescriptor(),0);
  43.  
  44.     /**
  45.      * A handle to the standard output stream. 
  46.      *
  47.      * @since   JDK1.0
  48.      */  
  49.     public static final FileDescriptor out 
  50.     = initSystemFD(new FileDescriptor(),1);
  51.  
  52.     /**
  53.      * A handle to the standard error stream. 
  54.      *
  55.      * @since   JDK1.0
  56.      */  
  57.     public static final FileDescriptor err 
  58.     = initSystemFD(new FileDescriptor(),2);
  59.  
  60.     /**
  61.      * Tests if this file descriptor object is valid.
  62.      *
  63.      * @return  <code>true</code> if the file descriptor object represents a
  64.      *          valid, open file or socket; <code>false</code> otherwise.
  65.      * @since   JDK1.0
  66.      */
  67.     public native boolean valid();
  68.  
  69.     /**
  70.      * Force all system buffers to synchronize with the underlying
  71.      * device.  This method returns after all modified data and
  72.      * attributes of this FileDescriptor have been written to the
  73.      * relevant device(s).  In particular, if this FileDescriptor
  74.      * refers to a physical storage medium, such as a file in a file
  75.      * system, sync will not return until all in-memory modified copies
  76.      * of buffers associated with this FileDesecriptor have been
  77.      * written to the physical medium.
  78.      *
  79.      * sync is meant to be used by code that requires physical
  80.      * storage (such as a file) to be in a known state  For
  81.      * example, a class that provided a simple transaction facility
  82.      * might use sync to ensure that all changes to a file caused
  83.      * by a given transaction were recorded on a storage medium.
  84.      *
  85.      * sync only affects buffers downstream of this FileDescriptor.  If
  86.      * any in-memory buffering is being done by the application (for
  87.      * example, by a BufferedOutputStream object), those buffers must
  88.      * be flushed into the FileDescriptor (for example, by invoking
  89.      * OutputStream.flush) before that data will be affected by sync.
  90.      *
  91.      * @exception SyncFailedException
  92.      *          Thrown when the buffers cannot be flushed,
  93.      *          or because the system cannot guarantee that all the
  94.      *          buffers have been synchronized with physical media.
  95.      * @since     JDK1.1
  96.      */
  97.     public native void sync() throws SyncFailedException;
  98.  
  99.     /**
  100.      * This routine initializes in, out and err in a sytem dependent way.
  101.      */
  102.     private static native FileDescriptor initSystemFD(FileDescriptor fdObj, 
  103.     int desc);
  104. }
  105.